import java.util.*;

public class  pro2 {
    public static int maxSubArray(int[] nums) {
        int curMax = nums[0], gloMax = nums[0];
        for (int i = 1; i < nums.length; i++) {
            curMax = Math.max(nums[i], curMax + nums[i]);
            gloMax = Math.max(gloMax, curMax);
        }
        return gloMax;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入整数数组（空格或逗号分隔）：");
        String line = sc.nextLine().trim();
        if (line.isEmpty()) return;

        // 统一把逗号换成空格，再按空白拆分
        String[] tokens = line.replace(',', ' ').split("\\s+");
        int[] nums = new int[tokens.length];
        for (int i = 0; i < tokens.length; i++) {
            nums[i] = Integer.parseInt(tokens[i]);
        }

        System.out.println("最大子数组和 = " + maxSubArray(nums));
    }
}